package com.inetools.gwetons.shared.logging;


/**
 * When sub-class does not have static method for logging, then extend from this, and obtain 
 * LogUtil instance for logging via getLogUtil method.<br />
 * For the class with static method, use getLogUtil method and getLogUtilFunctions method 
 * of LogUtilFactory class instead.
 * @author ay
 */
public abstract class LogUtilAdapterTemplate {
	// For logging --------------------------------------------------------------------------------
	abstract protected String getNameForLogging();
	
	protected final Object logUtilLock = new Object();
	
	private LogUtilFactoryIntf logUtilFactoryIntf;
		/**
		 * @return LogUtilFactoryIntf object held by logUtilFactoryIntf member field. <br />
		 * If logUtilFactoryIntf member field value is null when this method is called, then 
		 * LogUtilFactory.FacoryInstance will be set to logUtilFactoryIntf member field. 
		 */
		protected LogUtilFactoryIntf getLogUtilFactoryIntf() {
			synchronized( logUtilLock) {
				return logUtilFactoryIntf;
			} // synchronized
		}
		protected void setLogUtilFactoryIntf( LogUtilFactoryIntf logUtilFactoryIntf) {
			synchronized( logUtilLock) {
				this.logUtilFactoryIntf = logUtilFactoryIntf;
				setLogUtil( null);
			} // synchronized
		}
	
	private LogUtil logUtil;
		/**
		 * @return logUtil member field. <br />
		 * If logUtil member field value is null when this method is called, then it will be 
		 * obtained via getLogUtil method of logUtilFactoryIntf member field. At that time, if 
		 * logUtilFactoryIntf member field value is null, then LogUtilFactory.FacoryInstance 
		 * will be set to logUtilFactoryIntf member field. 
		 */
		protected LogUtil getLogUtil() {
			synchronized( logUtilLock) {
				if ( logUtil == null) {
					setLogUtil( 
							LogUtilFactory.getLogUtil( 
									getNameForLogging(), 
									getLogUtilFactoryIntf()
									)
							);
				}
				return logUtil;
			} // synchronized
		}
		protected void setLogUtil( LogUtil logUtil) {
			synchronized( logUtilLock) {
				this.logUtil = logUtil;
			} // synchronized
		}
	// --------------------------------------------------------------------------------------------
}
